<template>
  <div>
    <input type="file" :id="dcdom" @change ="uploadFile(this,dcdom)">
  </div>
</template>

<script>
export default {
  props: {
    dcdom:{
      type:String,
      default:'bigFile'
    },
    dckey:{
      type:String
    },
    notify_url:{
      type:String
    },
    dcConfig:{
      type:Object
    }
  },
  data() {
    return {
      dcUploadInit:null
    };
  },

  computed: {

  },

  watch: {
    dcConfig(newVal,oldVal){
    }
  },

  methods: {
      uploadFile(obj,domsize){
        let b = document.getElementById(domsize);
        //console.log(b.files);
        let file = b.files[0];
        let data = {};
        data.jsy_file_name = file.name;
        data.jsy_file_type = file.type;
        data.jsy_file_size = file.size;
        var extIndex = parseInt(file.name.lastIndexOf(".")) + 1;
        data.jsy_file_ext = file.name.substring(extIndex);
        this.dcUploadHttp(data);
      },
    // 金山云上传请求
    dcUploadHttp(data){
      let _this = this;
      this.dcUploadInit.start(
        {
          data,
          // 上传进度
          on_progress(index, count) {
          }
        },
        // 上传结束
        function(err, results) {
          if(err) return _this.$emit('dc-success',err);
          let successData = JSON.stringify(results);
          let returnData = eval("(" + successData + ")");
          return _this.$emit('dc-success',returnData);
        }
      );
    },
  },
  mounted () {
    //console.log(this.dcConfig);
    this.dcUploadInit = dcupload(this.dcConfig);
  },
};
</script>
